<html xmlns:th="http://www.thymeleaf.org"
      th:replace="~{fragments/layout :: layout (~{::body},'patients')}">

<body>

<h2>
    <th:block th:if="${visit['new']}">New</th:block>
    Visit
</h2>

<b>Patient</b>
<table class="table table-striped">
    <thead>
    <tr>
        <th>First Name</th>
        <th>Last Name</th>
        <th>Birth Date</th>
        <th>Address</th>
        <th>Phone Number</th>
    </tr>
    </thead>
    <tr>
        <td th:text="${patient.firstName}"/>
        </td>
        <td th:text="${patient.lastName}"/>
        </td>
        <td
                th:text="${#temporals.format(patient.birthDate, 'yyyy/MM/dd')}"/>
        </td>
        <td th:text="${patient.address}"/></td>
        <td th:text="${patient.phoneNumber}"></td>
    </tr>
</table>

<form th:object="${visit}" class="form-horizontal" method="post">
    <div class="form-group has-feedback">
        <input
                th:replace="~{fragments/inputField :: input ('Date', 'localDate', 'date')}"/>
        <input
                th:replace="~{fragments/inputField :: input ('Description', 'description', 'text')}"/>
    </div>

    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <input type="hidden" name="patientId" th:value="${patient.id}"/>
            <button class="btn btn-default" type="submit">Add Visit</button>
        </div>
    </div>
</form>

<br/>
<b>Previous Visits</b>
<table class="table table-striped">
    <tr>
        <th>Date</th>
        <th>Description</th>
    </tr>
    <tr th:if="${!visit['new']}" th:each="visit : ${patient.visits}">
        <td th:text="${#temporals.format(visit.localDate, 'yyyy/MM/dd')}"/>
        </td>
        <td th:text=" ${visit.description}"/>
        </td>
    </tr>
</table>

</body>
</html>
